package net.zoneland.knowledge.dao;

import java.util.List;
import net.zoneland.knowledge.model.DictItem;
import net.zoneland.knowledge.model.DictItemExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface DictItemMapper {
    @SelectProvider(type=DictItemSqlProvider.class, method="countByExample")
    long countByExample(DictItemExample example);

    @Insert({
        "insert into AITK_DIC_ITEM_INFO (ID, DICTVALUE, ",
        "DICTNAME, PARENTID, ",
        "ORDERS, DESCRIPTION, ",
        "CREATETIME)",
        "values (#{id,jdbcType=NVARCHAR}, #{dictValue,jdbcType=NVARCHAR}, ",
        "#{dictName,jdbcType=NVARCHAR}, #{parentId,jdbcType=NVARCHAR}, ",
        "#{orders,jdbcType=DECIMAL}, #{description,jdbcType=NVARCHAR}, ",
        "#{createtime,jdbcType=TIMESTAMP})"
    })
    int insert(DictItem record);

    @InsertProvider(type=DictItemSqlProvider.class, method="insertSelective")
    int insertSelective(DictItem record);

    @SelectProvider(type=DictItemSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="ID", property="id", jdbcType=JdbcType.NVARCHAR),
        @Result(column="DICTVALUE", property="dictValue", jdbcType=JdbcType.NVARCHAR),
        @Result(column="DICTNAME", property="dictName", jdbcType=JdbcType.NVARCHAR),
        @Result(column="PARENTID", property="parentId", jdbcType=JdbcType.NVARCHAR),
        @Result(column="ORDERS", property="orders", jdbcType=JdbcType.DECIMAL),
        @Result(column="DESCRIPTION", property="description", jdbcType=JdbcType.NVARCHAR),
        @Result(column="CREATETIME", property="createtime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<DictItem> selectByExample(DictItemExample example);

    @UpdateProvider(type=DictItemSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") DictItem record, @Param("example") DictItemExample example);

    @UpdateProvider(type=DictItemSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") DictItem record, @Param("example") DictItemExample example);

    @Select({"select dictname from AITK_DIC_ITEM_INFO where dictvalue=#{dictValue,jdbcType=NVARCHAR} and parentId=#{parentId,jdbcType=NVARCHAR}"})
    String getDictNameByValue(@Param("dictValue") String dictValue,@Param("parentId") String parentId);
}
